#pragma once

// 继承类因都需要保证先初始化数据,所以不使用锁

template <typename T>
class CSingleton
{
public:
    virtual ~CSingleton() {}

    CSingleton(CSingleton &) = delete;
    CSingleton(CSingleton &&) = delete;
    CSingleton &operator=(const CSingleton &) = delete;
    CSingleton &operator=(CSingleton &&rhs) = delete;

    static T *GetInstance()
    {
        if (nullptr == m_pInstance)
            m_pInstance = new T();

        return m_pInstance;
    }

protected:
    CSingleton() {}

    static T *m_pInstance;
};

template <typename T>
T *CSingleton<T>::m_pInstance = nullptr;